﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Umi.Web.Middleware.Sample
{
    public class SampleMiddleware
    {
        private readonly RequestDelegate next;
        private readonly ILogger logger;

        public SampleMiddleware(RequestDelegate next, ILogger<SampleMiddleware> logger)
        {
            this.next = next;
            this.logger = logger;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            IQueryCollection querys = context.Request.Query;
            foreach (var item in querys)
            {
                logger.LogDebug("Key is {0}, Values is {1}", item.Key, item.Value);
            }
            if (context.Request.HasFormContentType)
            {
                IFormCollection form = context.Request.Form;
                foreach (var item in form)
                {
                    logger.LogDebug("Key is {0}, Values is {1}", item.Key, item.Value);
                }
            }
            logger.LogInformation("request into Sample Middlewares");
            await next(context);
        }
    }
}
